//
//  MyAppTableViewCell.m
//  PgyHelper
//
//  Created by 鹏鹏 on 2020/11/12.
//  Copyright © 2020 CleverPeng. All rights reserved.
//

#import "MyAppTableViewCell.h"
#import "RequestTool.h"
#import "PPTools.h"

@interface MyAppTableViewCell()

@property (weak, nonatomic) IBOutlet UIButton *viewNewButton;

@property (weak, nonatomic) IBOutlet UIImageView *buildIconImageView;
@property (weak, nonatomic) IBOutlet UILabel *buildNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *buildVersionLabel;
@property (weak, nonatomic) IBOutlet UILabel *buildBuildVersionLabel;
@property (weak, nonatomic) IBOutlet UILabel *buildIdentifierLabel;
@property (weak, nonatomic) IBOutlet UILabel *buildVersionNoLabel;
@property (weak, nonatomic) IBOutlet UILabel *buildSizeLabel;
@property (weak, nonatomic) IBOutlet UIView *buildDescBGView;
@property (weak, nonatomic) IBOutlet UILabel *buildDescLabel;
@property (weak, nonatomic) IBOutlet UILabel *buildCreatedLabel;


@end

@implementation MyAppTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.buildIconImageView.layer.cornerRadius = 8;
    self.buildIconImageView.layer.masksToBounds = YES;

    self.buildDescBGView.layer.cornerRadius = 4;
    self.buildDescBGView.layer.masksToBounds = YES;
}

- (void)setAppModel:(MyAppModel *)appModel {
    _appModel = appModel;

    NSString *iconUrl = HOST_URL_app_icons(appModel.buildIcon);
    [self.buildIconImageView sd_setImageWithURL:[NSURL URLWithString:iconUrl] placeholderImage:[UIImage imageNamed:@"app_icon"]];
    self.buildNameLabel.text = appModel.buildName;
    self.buildVersionLabel.text = [NSString stringWithFormat:@"V%@", appModel.buildVersion];
    self.buildBuildVersionLabel.text = [NSString stringWithFormat:@"(%@)", appModel.buildBuildVersion];
    self.buildIdentifierLabel.text = [NSString stringWithFormat:@"%@", appModel.buildIdentifier];
    self.buildVersionNoLabel.text = [NSString stringWithFormat:@"Xcode build: %@", appModel.buildVersionNo];
    self.buildSizeLabel.text = [NSString stringWithFormat:@"大小: %@", [PPTools fileSizeFormat:[appModel.buildFileSize longLongValue]]];
    self.buildDescLabel.text = appModel.buildUpdateDescription;
    self.buildCreatedLabel.text = [NSString stringWithFormat:@"上传时间: %@", appModel.buildCreated];
}

- (IBAction)toViewNet:(id)sender {
    NSString *urlString = [NSString stringWithFormat:@"https://www.pgyer.com/%@", self.appModel.buildKey];
    NSString *buildPassword = self.appModel.buildPassword;
    [PPTools jumpToDownloadPage:urlString buildPassword:buildPassword];
}

- (IBAction)toInstallDirectly:(id)sender {
    [PPTools jumpToInstallDirectly:self.appModel.buildKey buildPassword:self.appModel.buildPassword];
}

@end
